package com.jk.order.mapper;

import com.jk.common.model.AddressBean;
import com.jk.common.model.ChinaAddressBean;
import com.jk.common.model.FlowerBean;
import com.jk.common.model.OrderBean;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Mapper
public interface OrderMapper {

    @Select("SELECT * from sys_city where pid=#{value}")
    List<ChinaAddressBean> getProviceBind(Integer pid);

    @Update("update  t_order set   orderNumber=#{orderNumber}  ")
    void updateById(String orderNumber);

   /* @Insert("insert into t_order(orderId,productId,createTime) values(#{orderId},#{productId},SYSDATE())")
    void saveOrder(OrderBean orderBean);*/
    @Insert("insert into t_address(userId,customerName,customerPhone,shengId,shiId,quId,customerAddress) value(#{userId},#{customerName},#{customerPhone},#{shengId},#{shiId},#{quId},#{customerAddress}) ")
    void saveUserAddress(AddressBean addressBean);

    @Insert("insert into t_order(orderNumber,orderCreateTime,userId,flowerIds,orderStatus) value(#{orderNumber},now(),#{userId},#{flowerIds},2)")
    void savaOrderNumber(@RequestParam("orderNumber") String orderNumber, @RequestParam("userId") String userId, @RequestParam("flowerIds") String flowerIds);

   /* @Select("select flowerName from t_flower where flowerId = #{value}")
    String findFlowerByFlowerId(int flowerId);*/

    @Select("SELECT s.cname as shengText,s2.cname as shiText,s3.cname as quText,customerName,customerPhone,userId,customerAddress,shengId,shiId,quId from t_address t LEFT JOIN sys_city s on t.shengId=s.id LEFT JOIN sys_city s2 on t.shiId=s2.id LEFT JOIN sys_city s3 on t.quId=s3.id where  t.userId=#{value}")
    AddressBean findUserAddress(String userId);

    @Select("select * from t_flower where flowerId=#{flowerId}")
    FlowerBean queryFlowerPrice(Integer flowerId);


}
